/* C库 */
#include "stdio.h"
#include "string.h"

/* RTOS */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/* 接口文件 */
#include "UniversalSerialPort.hpp"
#include "CompressorMotor.hpp"
#include "CompressorMotorService.hpp"

static TaskHandle_t  compressor_motor_task;

static void CompressorMotorService_task(void *pram){
    CompressorMotor * compressor_motor = CompressorMotor::getInstance();
    bool compressor_motor_ret = false;
    compressor_motor_ret = compressor_motor->enableMotor();
    printf("compressor_enableMotor:%s\r\n",compressor_motor_ret ? "True" : "False");

    compressor_motor_ret = compressor_motor->setSpeed(2000);
    printf("compressor_set_speed:%s\r\n",compressor_motor_ret ? "True" : "False");

    compressor_motor_ret = compressor_motor->open();
    printf("compressor_open:%s\r\n",compressor_motor_ret ? "True" : "False");

    vTaskDelay(8000);
    uint16_t speed = compressor_motor->getSpeedActual();
    printf("speed %d\r\n",speed);

    vTaskDelay(7000);
    compressor_motor_ret = compressor_motor->close();
    printf("compressor_close:%s\r\n",compressor_motor_ret ? "True" : "False");

    while(true){
        printf("compressor\r\n");
        vTaskDelay(2000);
    }
}

bool CompressorMotorService::run(){
    xTaskCreate(CompressorMotorService_task,"compressor_control_task",256,nullptr,3,&compressor_motor_task);
    return true;
}